﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
using TMS_BackEnd.IRepository.Shen;
using TMS_BackEnd.Models.SH;
using TMS_BackEnd.MyDbContexts;
using Volo.Abp.DependencyInjection;

namespace TMS_BackEnd.Repository.Shen
{
    [Dependency(ServiceLifetime.Singleton)]
    public class Sys_menuRepository : ISys_menuRepository
    {
        public MyDbContext myDbContext { get; set; }

        public int AddSys_menu(sys_menu sys_Menu)
        {
            string sql = $@"insert [dbo].[sys_menu](menu_name, parent_id, path, component, query, menu_type, visible, status, sys_menumenu_id)
            values('{sys_Menu.menu_name}','{sys_Menu.parent_id}','{sys_Menu.path}','{sys_Menu.component}','{sys_Menu.query}','{sys_Menu.menu_type}','{sys_Menu.visible}','{sys_Menu.status}','1')";
            int result = myDbContext.Database.ExecuteSqlRaw(sql);
            return result;
        }

        public int DelteSys_menu(int menu_id)
        {
            string sql = $@"delete [dbo].[sys_menu] where [menu_id]='{menu_id}'";
            int result = myDbContext.Database.ExecuteSqlRaw(sql);
            return result;
        }

        public List<sys_menu> Get_Menus()
        {
            string sql = $"select * from [dbo].[sys_menu]";
            //List<sys_menu> list= myDbContext.Set<sys_menu>().FromSqlRaw(sql).ToList();
            List<sys_menu> list= myDbContext.Sys_menus.FromSqlRaw(sql).ToList();
            return list;
        }

        public int UpdateSys_menu(sys_menu sys_Menu)
        {
            string sql = $@"update [dbo].[sys_menu] set [menu_name]='{sys_Menu.menu_name}' where [menu_id]='{sys_Menu.menu_id}'";
            int result=myDbContext.Database.ExecuteSqlRaw(sql);
            return result;
        }
    }
}
